<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(devildark) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("/var/www/log/devildark/log", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);


    $id = $arr2["MACAddress"];
    $id2 = $arr2["DailyGDLost"];
    $id3 = $arr2["RegisterTime"];
    $id4 = $arr2["RegisterDate"];
    $id5 = $arr2["LevelInfo"];
    $id6 = $arr2["DailyGamingTime"];
    $id7 = $arr2["GamingTime"];
    $id8 = $arr2["DailyTCTimes"];
    $id9 = $arr2["DailyLoginTimes"];
    $id10 = $arr2["DailyGDExchangeTimes"];

    $id11 = $arr2["DailyGDGetFromGame"];  //2
    $id12 = $arr2["DailyGDGetFromTC"];
    $id13 = $arr2["DailyTCGet"];
    $id14 = $arr2["JailBreak"];
    $id15 = $arr2["GDGet"]; //3
    $id16 = $arr2["TCGet"];
    $id17 = $arr2["DataTime"];
    $id18 = $arr2["DailyPlayerExpGet"];
    $id19 = $arr2["CurrentTC"]; //4
    $id20 = $arr2["CurrentPlayerLevel"];


    $id21 = $arr2["DailyTCLost"];
    $id22 = $arr2["CurrentGD"];
    //$id23 = $arr2["deviceid"];
    $id24 = $arr["gamename"];


    $id25 = $arr["createdate"];
    

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        $deviceid = $id;
        $DailyGDLost = $id2;
        $RegisterTime = $id3;
        $RegisterDate = $id4;
        $LevelInfo = $id5;
        $DailyGamingTime = $id6;
        $GamingTime = $id7;
        $DailyTCTimes = $id8;
        $DailyLoginTimes = $id9;
        $DailyGDExchangeTimes = $id10;
        $DailyGDGetFromGame = $id11;
        $DailyGDGetFromTC = $id12;
        $DailyTCGet = $id13;
        $JailBreak = $id14;
        $GDGet = $id15;
        $TCGet = $id16;
        $DataTime = $id17;
        $DataTimes = $id17;
        $DailyPlayerExpGet = $id18;
        $CurrentTC = $id19;
        $CurrentPlayerLevel = $id20;
        $DailyTCLost = $id21;
        $CurrentGD = $id22;
        //$deviceid = $id23;
        $gamename = $id24;

        $createdate = $id25;
    
        mysql_query("INSERT INTO devildark_query (deviceid,DailyGDLost,RegisterTime,RegisterDate,LevelInfo,
                                        DailyGamingTime,GamingTime,DailyTCTimes,DailyLoginTimes,DailyGDExchangeTimes,
                                        DailyGDGetFromGame,DailyGDGetFromTC,DailyTCGet,JailBreak,GDGet,TCGet,DataTime,
                                        DailyPlayerExpGet,CurrentTC,CurrentPlayerLevel,DailyTCLost,CurrentGD,gamename,createdate,date,DataTimes) 
                    VALUES('$deviceid','$DailyGDLost','$RegisterTime','$RegisterTime','$LevelInfo',
                        '$DailyGamingTime','$GamingTime','$DailyTCTimes','$DailyLoginTimes','$DailyGDExchangeTimes',
                           '$DailyGDGetFromGame','$DailyGDGetFromTC','$DailyTCGet','$JailBreak','$GDGet','$TCGet','$DataTime',
                           '$DailyPlayerExpGet','$CurrentTC',
                           '$CurrentPlayerLevel','$DailyTCLost','$CurrentGD','$gamename','$createdate','$createdate','$DataTime')") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
